const User = require('../../db/UserSchema');

module.exports = async(req, res) => {
    // 1.异常就是直接和数据库的规则不符的异常,不正常的异常
    // try...catch捕获程序执行的异常
    try {
        // var rel = await User.deleteOne({ '_id': '99999' });
        // var rel = await User.deleteOne({ '_id': '61cb3f74fb34e0395c98b222' });
        var rel = await User.deleteOne({ '_id': req.body.id });
        // { acknowledged: true, deletedCount: 1 }
        if (rel.deletedCount) {
            res.redirect('/admin/userlist');
        } else {
            // { acknowledged: true, deletedCount: 0 }
            res.send('<script>alert("删除用户信息不符")</script>');
        }
    } catch (error) {
        res.status(500).send('删除信息失败' + error);

    }
}